﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="roleManager.aspx.cs" Inherits="manager_systemSetting_roleManager" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <title>管理角色</title>
    <!-- iCheck -->
    <link href="/reference/plugins/iCheck/all.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder" runat="Server">
    <section class="content-header">
        <h1>管理角色
            <small>系统设置</small>
        </h1>
        <ol class="breadcrumb">
            <li><a><i class="fa fa-dashboard"></i>主页</a></li>
            <li><a href="roleManager.aspx">系统设置</a></li>
            <li class="active">管理角色</li>
        </ol>
    </section>
    <section class="content">

        <div class="box box-primary">
            <div class="box-header with-border">
                <div>
                    <div class="box-tools pull-left">
                        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#moduleManager" data-action="add">添加角色</button>
                    </div>
                </div>
            </div>
            <div class="box-body">
                <table id="moduleManagerList" class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th></th>
                            <th class="col-sm-4">名称</th>
                            <th>可用</th>
                            <th></th>
                            <th></th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        <asp:Repeater ID="rptmoduleManager" runat="server">
                            <ItemTemplate>
                                <tr>
                                    <td><a><%# Eval("ID").ToString() %></a></td>
                                    <td><a><%# Eval("roleName").ToString() %></a></td>
                                    <td><%# Eval("isUsing").ToString().Trim()=="True"?"<span style='color:green'>可用</span>":"<span style='color:red'>不可用</span>" %></td>
                                    <td><a data-toggle="modal" data-target="#rolePermissions" data-roleid="<%# Eval("ID") %>">权限</a></td>
                                    <td><a data-toggle="modal" data-target="#moduleManager" data-action="update" data-bid="<%# Eval("ID") %>">修改</a></td>
                                    <td><a onclick="deletemoduleManager(<%# Eval("ID") %>)">删除</a></td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                    </tbody>
                </table>
            </div>
            <div style="display: none">
                <asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="btnDelete_Click" />
            </div>

            <div class="modal fade" id="moduleManager" tabindex="-1" role="dialog" aria-labelledby="moduleManagerLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="moduleManagerLabel"></h4>
                        </div>
                        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
                        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                            <ContentTemplate>

                                <div style="display: none">
                                    <asp:Button ID="btnGet" runat="server" Text="Get" OnClick="btnGet_Click" />
                                </div>
                                <div class="modal-body">
                                    <asp:HiddenField ID="hidBID" runat="server" />
                                    <table class="table table-bordered">
                                        <tr>
                                            <td class="col-sm-2">名称</td>
                                            <td>
                                                <asp:TextBox ID="txtName" CssClass="form-control" runat="server"></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="col-sm-2">是否可用</td>
                                            <td>
                                                <asp:DropDownList ID="ddlIsUsing" CssClass="form-control" runat="server">
                                                    <asp:ListItem Value="1">是</asp:ListItem>
                                                    <asp:ListItem Value="0">否</asp:ListItem>
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                            <asp:Button ID="btnSave" runat="server" Text="确定" CssClass="btn btn-primary" OnClick="btnSave_Click" />
                            <asp:Button ID="btnUpdate" runat="server" Text="修改" CssClass="btn btn-primary" OnClick="btnUpdate_Click" />
                        </div>
                    </div>
                </div>
            </div>

            <div class="modal fade" id="rolePermissions" tabindex="-1" role="dialog" aria-labelledby="rolePermissionsLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="rolePermissionsLabel"></h4>
                        </div>
                        <asp:HiddenField ID="hidRoleID" runat="server" />
                        <asp:HiddenField ID="hidAddModule" runat="server" />
                        <asp:HiddenField ID="hidDelModule" runat="server" />
                        <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                            <ContentTemplate>
                                <div style="display: none">
                                    <asp:Button ID="btnGetPermissions" runat="server" Text="Get" OnClick="btnGetPermissions_Click" />
                                </div>
                                <div class="modal-body">
                                    <%=Html_Role %>
                                </div>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">
                                取消                               
                            </button>
                            <asp:Button ID="btnRoleSave" runat="server" Text="确定" CssClass="btn btn-primary" OnClientClick="SetRoleStr()" OnClick="btnRoleSave_Click" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div style="display: none">
            <input type="text" value="" runat="server" id="Trolestr" />
            <input type="text" value="" runat="server" id="TrolestrID_I" />
            <input type="text" value="" runat="server" id="TrolestrID_D" />
        </div>

    </section>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="ScriptPlaceHolder" runat="Server">
    <script>
        $(document).ready(function () {
            $("#moduleManagerList").DataTable(
                {
                    "columnDefs": [
                        { "targets": [0], "visible": false },
                        { "orderable": false, "targets": 1 },
                        { "orderable": false, "targets": 2 },
                        { "orderable": false, "targets": 3 },
                        { "orderable": false, "targets": 4 },
                        { "orderable": false, "targets": 5 }
                    ],
                    "autoWidth": false,
                    "order": [[0, "desc"]],
                    "language": {
                        "url": "/reference/plugins/datatables/Chinese.json"
                    }
                });
        });

        $('#moduleManager').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget)

            var action = button.data('action');
            if (action == "add") {
                $("#moduleManagerLabel").text("添加角色");
                $("#ContentPlaceHolder_btnSave").css("display", "");
                $("#ContentPlaceHolder_btnUpdate").css("display", "none");

                $("#ContentPlaceHolder_txtName").val("");
                $("#ContentPlaceHolder_ddlIsUsing").val("1");
            }
            else if (action == "update") {
                $("#moduleManagerLabel").text("修改角色");
                $("#ContentPlaceHolder_btnSave").css("display", "none");
                $("#ContentPlaceHolder_btnUpdate").css("display", "");

                var browserID = button.data('bid');
                $("#ContentPlaceHolder_hidBID").val(browserID);
                $("#ContentPlaceHolder_btnGet").click();
            }
        })

        $('#rolePermissions').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget)

            $("#rolePermissionsLabel").text("设置角色权限");

            var browserID = button.data('roleid');
            $("#ContentPlaceHolder_hidRoleID").val(browserID);
            $("#ContentPlaceHolder_btnGetPermissions").click();
        })

        function deletemoduleManager(mlID) {
            var f = confirm("确定要删除此角色吗?");
            if (f == true) {
                $("#ContentPlaceHolder_hidBID").val(mlID);
                $("#ContentPlaceHolder_btnDelete").click();
            }
        }

        function ClSe(type, sign, id, obj, pid) {
            if (type == "C") {
                if (obj.checked == true) {
                    if (!$("#parentt_" + pid).prop("checked")) {
                        $("#parentt_" + pid).prop('checked', true);
                    }
                }
                else {
                    var midbool = false;
                    $("input[name='childd_" + pid + "']:checkbox").each(function () {
                        if ($(this).prop("checked") && midbool == false) {
                            midbool = true;
                        }
                    });
                    if (midbool == false) {
                        $("#parentt_" + pid).prop('checked', false);
                    }
                }
            }
            else if (type == "P") {
                if (obj.checked == true) {
                    $("input[name='childd_" + pid + "']:checkbox").each(function () {
                        $(this).prop('checked', true);
                    });
                }
                else {
                    $("input[name='childd_" + pid + "']:checkbox").each(function () {
                        $(this).prop('checked', false);
                    });
                }
            }
        }

        function SetRoleStr() {
            $(":checkbox").each(function () {
                var midstr = $(this).val();
                var midstr2 = $("#ContentPlaceHolder_TrolestrID_I").val();
                var midstr3 = $("#ContentPlaceHolder_TrolestrID_D").val();

                var sign = midstr.split("_")[1];
                var id = midstr.split("_")[2];
                if ($(this).prop("checked")) {
                    if (sign == "I") {
                        midstr2 = midstr2 + "|" + id;
                        $("#ContentPlaceHolder_TrolestrID_I").val(midstr2);
                    }
                }
                else {
                    if (sign == "D") {
                        midstr3 = midstr3 + "|" + id;
                        $("#ContentPlaceHolder_TrolestrID_D").val(midstr3);
                    }
                }
            });
        }



    </script>
</asp:Content>

